SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO



--[utils].[udf_SplitString]('1=1.50','=')
CREATE function [utils].[udf_SplitString] 
(
@iSearchText nVARCHAR(max)
,@iSearchExpr VARCHAR(10) 
)
Returns @Results Table(id integer identity,SearchText nVARCHAR(max),ElementValue VARCHAR(8000))
As
BEGIN
Insert into @Results
(SearchText,ElementValue)
------- Split........
SELECT SearchText,
NullIf(SubString(SearchExpr + SearchText + SearchExpr , PositionedAt , CharIndex(SearchExpr , SearchExpr + SearchText + SearchExpr , PositionedAt) - PositionedAt) , '') AS SearchText
FROM (select numberid PositionedAt  from utils.numbers) Occurences, 
(
select 
@iSearchText as SearchText,
@iSearchExpr as SearchExpr
) dual
WHERE PositionedAt <= Len(SearchExpr + SearchText + SearchExpr) AND SubString(SearchExpr + SearchText + SearchExpr , PositionedAt - 1, 1) = SearchExpr 
AND CharIndex(SearchExpr , SearchExpr + SearchText + SearchExpr , PositionedAt) - PositionedAt > 0
------------ End of Split
Return
End




GO
